// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "UnrealClient.h"
#include "imageInfo.h"
#include "ShowFlags.h"

class UWorld;
class AActor;
class UCanvas;
class UGameInstance;
class UGameViewportClient;
class USTShotLocalPlayer;
class FCalcSceneViewTool;
/**
 * 
 */
class FScreenshotViewportClient:public FCommonViewportClient
{
	struct FWorldData 
	{
		UWorld* world;
		UGameInstance* gameInstance;
		UGameViewportClient* gameViewportClient;
		FWorldData();
		FWorldData(UWorld* w);
	};


	FWorldData worldData;
	FScreenshotInfo screenshotInfo;

	bool m_useHDR = false;
	
	FEngineShowFlags ScreenshotShowFlags;
	EViewModeIndex ViewModeIndex = EViewModeIndex::VMI_Lit;
	/** Current buffer visualization mode for this game viewport */
	float CustomSecondaruScreenPercentage = 100;

	int32 m_BlackBorders = 0;

	FName CurrentBufferVisualizationMode;
	/** Current Nanite visualization mode for this game viewport */
	FName CurrentNaniteVisualizationMode;

	/** Current Lumen visualization mode for this game viewport */
	FName CurrentLumenVisualizationMode;

	/** Current Strata visualization mode for this game viewport */
	FName CurrentStrataVisualizationMode;
	/** Current Groom visualization mode for this game viewport */
	FName CurrentGroomVisualizationMode;

	/** Current virtual shadow map visualization mode for this game viewport */
	FName CurrentVirtualShadowMapVisualizationMode;

	USTShotLocalPlayer* calcSceneLocalPlayer = nullptr;
public:


	FScreenshotViewportClient();
	virtual ~FScreenshotViewportClient();

	void InitViewportClient(UWorld* world);

	void SetEngineShowFlags(FEngineShowFlags Flags);
	void InitRenderTask(const FScreenshotInfo& info, FViewport* InViewport);
	void FlushRenderingRenderTask();

	virtual UWorld* GetWorld() const override;

	//~ Begin FViewportClient Interface.

	virtual void Precache() override;
	virtual void Draw(FViewport* InViewport, FCanvas* SceneCanvas) override;

	virtual TOptional<bool> QueryShowFocus(const EFocusCause InFocusCause) const override;

	virtual void LostFocus(FViewport* Viewport) override {;}
	virtual void ReceivedFocus(FViewport* Viewport) override {;}

	virtual bool IsFocused(FViewport* Viewport) override { return false; }


	virtual bool IsOrtho() const override;
	
private:
	UCanvas* GetCanvasByName(FName CanvasName);


	//~ End FViewportClient Interface.


	EViewStatusForScreenPercentage GetViewStatusForScreenPercentage()const;
	
};

